package cms.classroom.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

public class FileUtil {
	public static void writeFile(String fileName, String data) throws IOException {
	    FileWriter fw = new FileWriter(fileName);
	    PrintWriter out = new PrintWriter(fw);
	    out.write(data);
	    out.println();
	    fw.close();
	    out.close();
	}
	
	public static String ReadFile(String fileName) {
	    File file = new File(fileName);
	    BufferedReader reader = null;
	    String laststr="";
		try {
	        reader = new BufferedReader(new FileReader(file));
	        String tempString = null;
	        while ((tempString = reader.readLine())  != null) {
	            laststr = laststr + tempString;
	        }
	        reader.close();
	    } catch (IOException e) {
	        e.printStackTrace();
	    } finally {
	        if (reader != null) {
	            try {
	                reader.close();
	            } catch (IOException e1) {
	            }
	        }
	    }
	    return laststr;
	}
}
